<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="common/include :: header('编辑字典数据')"/>
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form" th:object="${sysDict}">
    <input type="hidden" name="id" th:field="*{id}"/>
    <input type="hidden" name="dictTypeCode" th:field="*{dictTypeCode}" />
                <div class="layui-form-item">
                    <label class="layui-form-label required">字典标签</label>
                    <div class="layui-input-block">
                        <input type="text" name="dictLabel" lay-verify="required"
                               lay-reqtext="字典标签不能为空" placeholder="请输入字典标签"
                               th:field="*{dictLabel}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">字典键值</label>
                    <div class="layui-input-block">
                        <input type="text" name="dictValue" lay-verify="required"
                               lay-reqtext="字典键值不能为空" placeholder="请输入字典键值"
                               th:field="*{dictValue}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">字典排序</label>
                    <div class="layui-input-block">
                        <input type="text" name="sort" lay-verify="required"
                               lay-reqtext="字典排序不能为空" placeholder="请输入字典排序"
                               th:field="*{sort}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">启用状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|禁用"
                               th:checked="${sysDict.status == '1' ? false : true}">
                    </div>
                </div>

                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">备注信息</label>
                    <div class="layui-input-block">
                        <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息"
                                  th:field="*{remark}"></textarea>
                    </div>
                </div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<th:block th:include="common/include :: footer"/>

<script th:inline="javascript">
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            data.field.status = $("input[name='status']").is(':checked') == true ? 0 : 1;
            $.ajax({
                url: ctx + 'sysDict/update',
                type: 'POST',
                async: false,
                contentType: 'application/json; charset=UTF-8',
                dataType: "json",
                data: JSON.stringify(data.field),
                success: function (res) {
                    var index = layer.alert(res.msg, {
                        title: '提示信息'
                    }, function () {
                        // 重新加载列表
                        window.parent.location.reload();
                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    });
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.close(index);
                    if (XMLHttpRequest.status == 404) {
                        window.location.href = "404";
                    } else {
                        layer.msg("服务器好像出了点问题！请稍后试试");
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>